package com.neusoft.weekreport.component.controller;

import com.neusoft.weekreport.component.bizService.ExportWeekToExcelService;
import com.neusoft.weekreport.component.req.ExportWeekInfoReq;
import com.neusoft.weekreport.component.req.GetWeekDetailListReq;
import com.neusoft.weekreport.component.resp.GetGroupInfoByIdResp;
import com.neusoft.weekreport.component.resp.GetGroupInfoListResp;
import com.neusoft.weekreport.component.resp.ResponseBean;
import com.neusoft.weekreport.component.resp.StringResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@EnableTransactionManagement
@RequestMapping("/exportWeek")
public class ExportWeekToExcelController {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    ExportWeekToExcelService exportWeekToExcelService;

    //导出周报到excel
    @RequestMapping(value="/exportWeekInfo",method = RequestMethod.POST)
    public void exportWeekInfo(@RequestBody  ExportWeekInfoReq req, HttpServletResponse response){

        try{
            exportWeekToExcelService.exportWeekInfo(req,response);
        }catch (Exception e){
            logger.error(e.toString());
        }
    }

    //传回文件名字
    @RequestMapping(value = "/getMonthWeek",method = RequestMethod.POST)
    public ResponseBean<StringResp> getMonthWeek(@RequestBody ExportWeekInfoReq req,HttpServletRequest request){
        ResponseBean<StringResp> responseBean = new ResponseBean<>();
        try{
            StringResp stringResp = exportWeekToExcelService.getMonthWeek(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"获取文件名称成功",stringResp);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }


}
